package com.test.mytest.jfreechart;

import java.awt.Font;
import java.io.File;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultKeyedValues2DDataset;

public class MyJFreeChart {
 
      public static void main(String[] args) {
                MyJFreeChart nn = new MyJFreeChart();
        try {
            nn.create();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
 
    public void create() throws Exception {
 
        DefaultKeyedValues2DDataset data = new DefaultKeyedValues2DDataset();
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 10; j++) {
                double random = Math.random();
				data.addValue(random, "r"+i, "c" + j);
                System.out.println(random);
            }
        }
 
        JFreeChart chart = ChartFactory.createLineChart(
                "标题", "x轴",
                "y轴", data,
                PlotOrientation.VERTICAL, true, false, false);
        chart.setTitle(new TextTitle("标题", new Font("宋体", 0, 10)));
        CategoryPlot plot = chart.getCategoryPlot();
        // x轴转向45度
 
        LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) plot.getRenderer();
        lineandshaperenderer.setDrawOutlines(false);
        ChartUtilities.saveChartAsJPEG(new File("E:\\test\\a.jpeg"), chart, 400,400);
              
        }
}
